#include<stdio.h>
#include<malloc.h>

int *extend(int *first,int *second,int firstsize,int secondsize){
	int *new;
	int i,newsize,j,p;
	newsize=firstsize + secondsize;
	new=(int *) malloc((newsize) * (sizeof(int)));
	for(i=0;i<firstsize;i++){
		new[i]=first[i];
			   }
	for(j=(firstsize),p=0;j<newsize,p<secondsize;j++,p++){
		new[j]=second[p];
			}
	printf("the new list is:");
	for(i=0;i<newsize;i++){
		printf("%d ",new[i]);
		}
return new;
}

int *delete(int *ar,int value,int size){
	int i,j;
	int *p;
        p=(int *) malloc((size-1) * (sizeof(int)));	
	i=0;j=0;	
	while((i<size) && j<(size-1)){
		if(ar[i]!=value){
			p[j]=ar[i];
			i=i+1;
			j=j+1;
			}
		else{
			i=i+1;
			}
		}
	printf("the deleted list is:");
	for(i=0;i<(size-1);i++){
		printf("%d ",p[i]);
		}
					
return p;
}
int index1(int *ar,int value,int size){
	int i,r;
	for(i=0;i<size;i++){
		if(ar[i]==value){
			r=i;
			break;
			break;	}
		else{
			r=999999;
			}
		}
	printf("the index is: %d\n",r);
	return 0;
}

int *insert(int *ar,int in,int value,int size){
	int *q;
	int i,j;
	q=(int *) malloc( (size+1) * (sizeof(int)));
	i=0;
	j=0;
	while((i<size) && (j<size+1)){
		if(i==in){
			q[j]=value;
			j=j+1;			
			}		
		else{
			q[j]=ar[i];			
			i=i+1;
			j=j+1;
						
			}
		}		
	printf("the new inserted list is:");
	for(i=0;i<size+1;i++){
		printf("%d ",q[i]);
		}
return q;
}
int *sorti(int *ar,int size){
	int i;
	int j;
	int temp;
	for(i=0;i<size;i++){
		for(j=i+1;j<size;j++){
			if(ar[j]<ar[i]){
				temp=ar[j];
				ar[i]=ar[j];
				ar[j]=temp;
				}}}
	printf("the sorted list is:");
	for(i=0;i<size;i++){
		printf("%d ",ar[i]);
			}
	return *ar;
}
int main(){
int *a;
int *g;
a=(int *) malloc(4 * (sizeof(int)));
g=(int *) malloc(3 * (sizeof(int)));
a[0]=21;a[1]=23;a[2]=45;a[3]=100;
g[0]=101;g[1]=102;g[2]=103;
//extend(a,g,4,3);
//delete(a,45);
//index1(a,23);
insert(g,1,199,3);
return 0;
}

		

